<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\GroupGoodslist;
use App\Models\GroupGood;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class GroupGoodslistController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new GroupGoodslist(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('portrait')->image('',100,100);
            $grid->column('group_id');
            $grid->column('group_starttime');
            $grid->column('group_goods');
            $grid->column('end_time');
            $grid->column('status');
            $grid->status
                ->using([1 => '已完成', 0 => '未完成'])
                ->dot(
                    [
                        1 => 'success',
                        0 => 'danger',
                    ],
                    'primary' // 默认颜色
                );
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new GroupGoodslist(), function (Show $show) {
            $show->field('id');
            $show->field('portrait');
            $show->field('group_id');
            $show->field('group_starttime');
            $show->field('group_goods');
            $show->field('end_time');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new GroupGoodslist(), function (Form $form) {
            $form->display('id');
            $form->file('portrait')->disk('qiniu')->saveFullUrl('http://ocdn.xiaxuele.top/');
            $form->select('group_id','团长id')->options('userid');
            $form->datetime('group_starttime')->format('YYYY-MM-DD HH:mm:ss');
            $form->text('group_goods');
            $form->datetime('end_time')->format('YYYY-MM-DD HH:mm:ss');
            $form->text('status');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }

    public function userid(){
        $data = GroupGood::select('id','group_id')->get();
        foreach ($data as $k=>$v){
            $datas[$k]['id']=$v['id'];
            $datas[$k]['text'] =$v['group_id'];
        }
        return $datas;
    }
}
